<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'crawler-categories-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'website_id'); ?>
		<?php echo $form->dropDownList($model,'website_id',$websites); ?>
		<?php echo $form->error($model,'website_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'pattern_link'); ?>
		<?php echo $form->textField($model,'pattern_link',array('size'=>60,'maxlength'=>100)); ?>
		<?php echo $form->error($model,'pattern_link'); ?>
	</div>
	<?php $i = 1;?>
  <script>
  $(document).ready(function() {
	  vendor_index = <?php echo $i;?>;
	  $("#btn_add_congviec").click(function(){
		  vendor_index++;
		  $('#table_congviec').append('<tr><td>'+vendor_index+'<input type="hidden" name="countsgc[]" value="'+vendor_index+'" /></td><td><textarea name="CrawlerPatterns[name'+vendor_index+']" rows="6" cols="30"/></textarea></td><td class=\"row\"><textarea name="CrawlerPatterns[pattern'+vendor_index+']" rows="6" cols="30" /></textarea></td><td class=\"row\"><select id="CrawlerPatterns_type" name="CrawlerPatterns[type'+vendor_index+']"><option selected="selected" value="0">DOM</option><option value="1">REGEX</option></select></td></tr>');
	  });
  });
  </script>
  <b>Mẫu để tách dữ liệu</b>
  <table id="table_congviec">
    <tr>
    	<td>STT</td>
      <td>Tên trường</td>
      <td>Mẫu</td>
      <td>Loại</td>
    </tr>
		<?php if($model->isNewRecord):?>
	    <tr>
	      <td><?php echo $i;?><input type="hidden" name="countsgc[]" value="<?php echo $i;?>" /></td>
		    <td>
		    <?php echo Chtml::textArea('CrawlerPatterns[name'.$i.']','',array('rows'=>6, 'cols'=>30)); ?>
		  </td>
		  <td class="row">
			<?php echo Chtml::textArea('CrawlerPatterns[pattern'.$i.']','',array('rows'=>6, 'cols'=>30)); ?>
		  </td>
		  <td class="row">
			<?php echo Chtml::dropDownList('CrawlerPatterns[type'.$i.']', 0, Yii::app()->params['patternTypes']); ?>
		  </td>
		 </tr>
	<?php else:?>
		<?php if($model1):?>
			<?php foreach($model1 as $m){
			?>
			<tr>
		      <td><?php echo $i;?><input type="hidden" name="countsgc[]" value="<?php echo $i;?>" /></td>
			    <td>
			    <?php echo Chtml::textArea('CrawlerPatterns[name'.$i.']',$m->name,array('rows'=>6, 'cols'=>30)); ?>
			  </td>
			  <td class="row">
				<?php echo Chtml::textArea('CrawlerPatterns[pattern'.$i.']',$m->pattern,array('rows'=>6, 'cols'=>30)); ?>
			  </td>
			  <td class="row">
				<?php echo Chtml::dropDownList('CrawlerPatterns[type'.$i.']', $m->type, Yii::app()->params['patternTypes']); ?>
			  </td>
			 </tr>
			<?php
				$i++;
				}
			?>
		<?php endif;?>
	<?php endif;?>
  </table>
  <div class="row"><input type="button" name="btn_add_congviec" id="btn_add_congviec" value="Thêm trường"/></div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->